public class GetLongestPalindrome {
    public int getLongestPalindrome (String A) {
        // write code here
        // dp[i][j]表示[i,j]之间的字符串是否是回文串
        // leftIndex、rightIndex记录最长回文串的左起点和右起点
        int maxLength = 0;
        int len = A.length();
        char[] c = A.toCharArray();
        boolean[][] dp = new boolean[len][len];
        for (int i = 0; i < len; i++) {
            for (int j = 0; j <= i; j++) {
                if (c[i] == c[j]) {
                    if (j+1 > i-1 || dp[j+1][i-1]) {
                        dp[j][i] = true;
                        if (i-j+1 > maxLength) {
                            maxLength = i-j+1;
                        }
                    }
                }
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        GetLongestPalindrome obj = new GetLongestPalindrome();
        System.out.println(obj.getLongestPalindrome("abbba"));
    }
}
